package com.bawei.module_mine.audit.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.base.utils.LoggerUtils
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.module_mine.R
import com.bawei.module_mine.adapter.AuditCarAdapter
import com.bawei.module_mine.adapter.AuditVisitAdapter
import com.bawei.module_mine.audit.AuditViewModel
import com.bawei.module_mine.databinding.FragmentVisitAuditBinding
import com.bawei.myclub.base.mvvm.view.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class VisitAuditFragment : BaseFragment<AuditViewModel, FragmentVisitAuditBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_visit_audit
    override val mViewModel: AuditViewModel by viewModels()
    private val mAuditVisitAdapter: AuditVisitAdapter by lazy {
        AuditVisitAdapter()
    }
    override fun initView() {
        initAdapter()
    }
    override fun initData() {
        mViewModel.getVisitList()
    }

    override fun initListener() {
        mViewModel.visitEvent.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {}
                Loading -> {}
                Success -> {
                    LoggerUtils.d("fragment3","成功"+mViewModel.parkingList)
                    mAuditVisitAdapter.setVisitData(mViewModel.visitList)
                }
            }
        }
    }
    private fun initAdapter() {
        mAuditVisitAdapter.setupLayoutManager(mBinding.auditRec)
        mBinding.auditRec.adapter = mAuditVisitAdapter
    }

    override fun onResume() {
        super.onResume()
        mViewModel.getVisitList()
    }

}